﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace cpmntctrl
{
    public class ControlComponent
    {
        public static void UnVisibleCells(DataGridView aDataGridView,int k)
        {
            aDataGridView.Columns[k].Visible = false;
        }

        public static void UnVisibleCells(DataGridView aDataGridView,params int[] k)
        {
            Array.ForEach(k,i=>aDataGridView.Columns[i].Visible=false);
        }

        public static void AddToList(List<string> aList, DataGridView aDataGridView, DataGridViewCellEventArgs e, int k)
        {
            aList.Add(Convert.ToString(aDataGridView[k,e.RowIndex].Value));
        }

        public static void AddToList(List<string> aList, DataGridView aDataGridView, DataGridViewCellEventArgs e,params int[] k)
        {
            aList.AddRange(k.Select(i => Convert.ToString(aDataGridView[i, e.RowIndex].Value)));
        }

        public static void RemoveCells(List<string> id,DataGridView aDataGridView,int aCoulumn)
        {
            for (int i = 0; i < aDataGridView.RowCount; i++)
            {
                if (Convert.ToBoolean(aDataGridView[aCoulumn, i].Value) != true)
                {
                    id.Add(Convert.ToString(i));
                }
            }
            id.Reverse();
            foreach (var i in id)
            {
                aDataGridView.Rows.RemoveAt(Convert.ToInt32(i));
            }
        }

        /*public static void PaintNumberCells(DataGridView aDataGridView)
        {
            aDataGridView.RowHeadersWidthSizeMode=DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
            aDataGridView.RowPrePaint += DataGridView1RowPrePaint;
        }
        private static void DataGridView1RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            
            object value = ((DataGridView) sender).Rows[e.RowIndex].HeaderCell.Value;
            if (value==null||!value.Equals((e.RowIndex+1).ToString()))
            {
                ((DataGridView) sender).Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex+1).ToString(CultureInfo.InvariantCulture);
            }
        }*/
        #region Check
        public static void Check(DataGridView aDataGridView,DataGridViewCellEventArgs e,int column)
        {
            if (e.RowIndex == -1 || e.ColumnIndex == -1)
            {
                return;
            }
            if (Convert.ToString(aDataGridView[column, e.RowIndex].Value) == "" || Convert.ToBoolean(aDataGridView[column, e.RowIndex].Value) == false)
            {
                aDataGridView[2, e.RowIndex].Value = true;
            }
            else
            {
                aDataGridView[2, e.RowIndex].Value = false;
            }
        }
        public static bool Check(params TextBox[] aTextBox)
        {
            int k = aTextBox.Count(textBox => textBox.Text.Length > 0);
            return k == aTextBox.Count();
        }
        public static bool Check(params ComboBox[] aComboBox)
        {
            int k = aComboBox.Count(comboBox => comboBox.SelectedValue != null);
            return k==aComboBox.Count();
        }
        #endregion
        #region ClearMethod
        public static void Clear(TextBox aTextBox)
        {
            aTextBox.Clear();
            aTextBox.Focus();
        }
        public static void Clear(TextBox aTextBox2, TextBox aTextBox1)
        {
            aTextBox1.Clear();
            aTextBox2.Clear();
            aTextBox1.Focus();
        }
        public static void Clear(params TextBox[] aTextBox)
        {
            foreach (var textBox in aTextBox)
            {
                textBox.Clear();
            }
            aTextBox[0].Focus();
        }
        public static void Clear(ComboBox aComboBox)
        {
            aComboBox.DataSource = null;
            aComboBox.Items.Clear();
        }
        public static void Clear(ComboBox aComboBox1,ComboBox aComboBox2)
        {
            aComboBox1.DataSource = null;
            aComboBox1.Items.Clear();
            aComboBox2.DataSource = null;
            aComboBox2.Items.Clear();
        }
        public static void Clear(params ComboBox[] aComboBox)
        {
            foreach (var comboBox in aComboBox)
            {
                comboBox.DataSource = null;
                comboBox.Items.Clear();
            }
        }
        public static void Clear(ListBox aListBox)
        {
            aListBox.Items.Clear();
        }
        public static void Clear(ListBox aListBox1,ListBox aListBox2)
        {
            aListBox1.Items.Clear();
            aListBox2.Items.Clear();
        }
        public static void Clear(params ListBox[] aListBox)
        {
            foreach (var listBox in aListBox)
            {
                listBox.Items.Clear();
            }
        }
        #endregion

        
    }
}
